package com.example.goodpet.activity.Fragment;

import androidx.recyclerview.widget.RecyclerView;

import android.view.View;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.example.goodpet.R;
import com.example.goodpet.activity.adapter.PetTipsAdapter;
import com.example.goodpet.base.BaseFragment;
import com.example.goodpet.home.homeRecommend.bean.Tips;

import java.util.LinkedList;
import java.util.List;


public class TipsContentFragment extends BaseFragment {
    private String TAG = this.getClass().getSimpleName();

    private Tips.ResultDTO result;
    private RecyclerView rvContentMain;

    private VirtualLayoutManager layoutManager;
    private PetTipsAdapter adapter;
    private List<DelegateAdapter.Adapter> subAdapters = new LinkedList();

    private int type;


    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.fragment_tips_content, null);
        rvContentMain=view.findViewById(R.id.rv_content_main);
        return view;
    }

    public void setData(Tips.ResultDTO result,int type){
        this.result=result;
        this.type=type;
    }
    @Override
    public void initData() {
        //1.设置总布局管理器
        layoutManager = new VirtualLayoutManager(mContext);
        rvContentMain.setLayoutManager(layoutManager);
        //2.设置回收池大小（相同类型的View可以复用，防止多次创建ItemView）
        RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
        viewPool.setMaxRecycledViews(0, 10);
        rvContentMain.setRecycledViewPool(viewPool);
        //3.逐个设置子模块适配器
        addContentAdapter();

        //4.设置总适配器
        DelegateAdapter mainAdapter = new DelegateAdapter(layoutManager, true);
        mainAdapter.setAdapters(subAdapters);
        rvContentMain.setAdapter(mainAdapter);
    }

    private void addContentAdapter() {
        adapter = new PetTipsAdapter(mContext, result,type);
        subAdapters.add(adapter);
    }
}